﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Inc
{
    public class Types
    {
        public static Assembly GetAssembly(String typeName, ref Type _type)
        {
            foreach (Assembly currentassembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type t = currentassembly.GetType(typeName, false, true);
                if (t != null)
                {
                    _type = t;
                    return currentassembly;
                }
            }

            return null;
        }

        public static bool CheckBaseType(Type original, Type tosearch, int level = 5)
        {
            if (original == null || tosearch == null || level <= 0) return false;
            if (tosearch == typeof(object)) return true;

            Type _chType = original;
            for (int i = 0; i < level; i++)
            {
                if (_chType == null) return false;
                if (_chType == tosearch)
                {
                    _chType = null;
                    break;
                }
                else
                {
                    if (_chType.BaseType != typeof(object)) _chType = _chType.BaseType;
                    else break;
                }
            }
            if (_chType == null) return true;
            return false;
        }

    }
}
